import { reqgCategoryList, reqGetBannerList, reqFloorList } from '../../api'


const actions = {
    // 注意这里收到的参数是context，context是一个对象，我们需要里面的commit，所以这里直接把commit解构出来
    async categroyList({ commit }) {
        let result = await reqgCategoryList();
        if(result.code == 200){
            commit("CATEGORYLIST", result.data)
        }
        
    },
    async getBannerList({ commit }) {
        
        let result = await reqGetBannerList()
        if(result.code == 200){
            commit('BANNERLIST', result.data)
        }
       
    },
    async getFloorList({ commit }) {
        let result = await reqFloorList()
        if(result.code == 200) {
            commit('FLOORLIST',result.data)
        }
       
    }

}

const mutations = {
    // 因为vuex的state和vue的data一样，以数据代理的通过get set 把state放到了mutations中,这里的categroyList就是result.data
    CATEGORYLIST(state, categroyList) {
        // 将左边的值赋给右边
        state.categroyList = categroyList
    },
    BANNERLIST(state, bannerlist) {
        state.bannerList = bannerlist
    },
    FLOORLIST(state,floorlist){
        state.floorlist = floorlist
    }

}

const state = {
    //state中数据默认初始值别瞎写,根据后端返回的值进行填写，如果后端放回的是对象，就用对象的格式接收
    categroyList: [],
    // 轮播图
    bannerList: [],
    floorlist: []

}

const getters = {

}
export default {
    actions,
    mutations,
    state,
    getters
}